unit ReadersListDlg;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Mask, ExtCtrls, ppProd, ppClass, ppReport, ppComm, ppRelatv,
  ppCache, ppDB, ppDBPipe, ppCtrls, ppPrnabl, ppBands, ppViewr;

type
  TfmReadersListDlg = class(TForm)
    Bevel1: TBevel;
    Label1: TLabel;
    edBegDate: TMaskEdit;
    edEndDate: TMaskEdit;
    Label2: TLabel;
    btnReport: TButton;
    btnCancel: TButton;
    rgOtdel: TRadioGroup;
    ppDBPipeline1: TppDBPipeline;
    ppReport1: TppReport;
    ppHeaderBand1: TppHeaderBand;
    ppDetailBand1: TppDetailBand;
    ppFooterBand1: TppFooterBand;
    ppDBText1: TppDBText;
    ppDBText2: TppDBText;
    ppDBText3: TppDBText;
    ppDBText4: TppDBText;
    ppDBText5: TppDBText;
    ppDBText6: TppDBText;
    ppLabel1: TppLabel;
    ppLabel2: TppLabel;
    ppLabel3: TppLabel;
    ppLabel4: TppLabel;
    ppLabel5: TppLabel;
    ppLabel6: TppLabel;
    ppReport2: TppReport;
    ppHeaderBand2: TppHeaderBand;
    ppLabel7: TppLabel;
    ppLabel8: TppLabel;
    ppLabel9: TppLabel;
    ppLabel10: TppLabel;
    ppLabel11: TppLabel;
    ppLabel12: TppLabel;
    ppDetailBand2: TppDetailBand;
    ppDBText7: TppDBText;
    ppDBText8: TppDBText;
    ppDBText9: TppDBText;
    ppDBText10: TppDBText;
    ppDBText11: TppDBText;
    ppDBText12: TppDBText;
    ppFooterBand2: TppFooterBand;
    ppReport3: TppReport;
    ppHeaderBand3: TppHeaderBand;
    ppLabel13: TppLabel;
    ppLabel15: TppLabel;
    ppLabel16: TppLabel;
    ppLabel17: TppLabel;
    ppLabel18: TppLabel;
    ppDetailBand3: TppDetailBand;
    ppDBText13: TppDBText;
    ppDBText15: TppDBText;
    ppDBText16: TppDBText;
    ppDBText17: TppDBText;
    ppDBText18: TppDBText;
    ppFooterBand3: TppFooterBand;
    ppGroup1: TppGroup;
    ppGroupHeaderBand1: TppGroupHeaderBand;
    ppGroupFooterBand1: TppGroupFooterBand;
    ppGroup3: TppGroup;
    ppGroupHeaderBand3: TppGroupHeaderBand;
    ppGroupFooterBand3: TppGroupFooterBand;
    ppGroup2: TppGroup;
    ppGroupHeaderBand2: TppGroupHeaderBand;
    ppGroupFooterBand2: TppGroupFooterBand;
    procedure btnCancelClick(Sender: TObject);
    procedure btnReportClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ppReport1PreviewFormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fmReadersListDlg: TfmReadersListDlg;

implementation

uses DataModule, ListReaders;

{$R *.DFM}

procedure TfmReadersListDlg.FormCreate(Sender: TObject);
begin
  SetStatDates(edBegDate, edEndDate);
end;

procedure TfmReadersListDlg.btnCancelClick(Sender: TObject);
begin
  Self.Close;
end;

procedure TfmReadersListDlg.btnReportClick(Sender: TObject);
var beg_d,end_d : TDate;

begin
  try
    beg_d := StrToDate(edBegDate.Text);
    end_d := StrToDate(edEndDate.Text);
  except
    On E : Exception do exit;
  end;
  with dmData.qListReg do begin
    if Active then Close;
    SQL.Clear;
    Case rgOtdel.ItemIndex of
      0, 1: begin
         SQL.Add('SELECT N_KARD, CARD_NO, NAME, DATE_REG, READER_GROUP, CARD_DATE_REG');
         SQL.Add('FROM READER_CARDS_VIEW');
         SQL.Add('WHERE CARD_OTDEL = :OTDEL AND CARD_DATE_REG BETWEEN :BEG_DATE AND :END_DATE');
         SQL.Add('ORDER BY CARD_NO');
         ParamByName('OTDEL').AsInteger := rgOtdel.ItemIndex + 1;
       end;
      {1: begin
         SQL.Add('SELECT N_KARD, N_CHZ, NAME, DATE_REG, READER_GROUP, DATE_REREG_CHZ, NOM_CHZ');
         SQL.Add('FROM READERS_NEW');
         SQL.Add('WHERE DATE_REREG_CHZ >= :BEG_DATE AND  DATE_REREG_CHZ <= :END_DATE');
         SQL.Add('ORDER BY DATE_REREG_CHZ, NOM_CHZ');
       end;}
      else begin
         SQL.Add('SELECT N_KARD, NAME, DATE_REG, READER_GROUP, DATE_REREG, NOM_CARD');
         SQL.Add('FROM READERS_NEW');
         SQL.Add('WHERE DATE_REREG >= :BEG_DATE AND DATE_REREG <= :END_DATE');
         SQL.Add('ORDER BY DATE_REREG, NOM_CARD');
      end;
    end;
    ParamByName('BEG_DATE').AsDateTime := beg_d;
    ParamByName('END_DATE').AsDateTime := end_d;
    Prepare;
    Open;
    ppDBPipeline1.DataSource := dmData.dsListReg;
    case rgOtdel.ItemIndex of
      0, 1: ppReport1.Print;
      2:    ppReport3.Print;
    end;
  end;
end;

procedure TfmReadersListDlg.ppReport1PreviewFormCreate(Sender: TObject);
begin
  with Sender as TppReport do begin
    PreviewForm.WindowState := wsMaximized;
    TppViewer(PreviewForm.Viewer).ZoomSetting := zs100Percent;
  end;
end;

end.
